import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-05-23
 * Time: 19:52
 */
public class Test {
    public static void initOrder(int[] array){ //initialization 初始化的意思
        for (int i = 0; i < array.length; i++) {
            array[i] = i;//顺或逆序数组
        }
    }
    public static void norOrder(int[] array){  //随机产生数然后赋值给array数组
        Random random = new Random();
        for (int i = 0 ; i < array.length ; i++){
            array[i] = random.nextInt(10000);//产生随机数的范围1——10000
        }

    }
    public static void testInsertSort(int[] array){  //测试插入排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);
        long startTime = System.currentTimeMillis();
        Sort.inSertSort(array1);
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("插入排序所用的时间"+result);
    }
    public static void testShellSort(int[] array) {//测试希尔排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);
        long startTime = System.currentTimeMillis();
        Sort.shellSort(array1);
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("希尔排序所用的时间"+result);
    }
    public static void testSelectSort(int[] array) {//测试选择排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);
        long startTime = System.currentTimeMillis();
        Sort.selectSort(array1);//这里是不同点
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("选择排序所用的时间"+result);
    }
    public static void testSelecSort2(int[] array) {//测试双向选择排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);
        long startTime = System.currentTimeMillis();
        Sort.selectSort2(array1);
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("双向选择排序所用的时间"+result);
    }
    public static void testHeapSort(int[] array) {//测试堆排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);
        long startTime = System.currentTimeMillis();
        Sort.heapSort(array1);
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("堆排序所用的时间"+result);
    }
    public static void testBubbleSort(int[] array) {//测试冒泡排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);
        long startTime = System.currentTimeMillis();
        Sort.bubbleSort(array1);
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("冒泡排序所用的时间"+result);
    }
    public static void testHoareSort(int[] array) {//测试希尔排序所用时间
        int[] array1 = Arrays.copyOf(array,array.length*2);//扩容后，无序了？？？
        long startTime = System.currentTimeMillis();
        Sort.quickSort(array1);//没有进行扩容的时候可以排序
        long endTime = System.currentTimeMillis();
        long result = endTime - startTime;
        System.out.println("快速排序所用的时间"+result);
    }
    public static void main(String[] args) {
        int[] array1 = {10,20,30,23,12,23,43};
        Sort.inSertSort(array1);
        System.out.println("测试插入排序"+ Arrays.toString(array1));


        int[] array2 = {1,5,34,65,21,33,41,2,45,34,6,65,41,5,43};
        Sort.shellSort(array2);
        System.out.println("测试希尔排序"+Arrays.toString(array2));

        int[] array3 = {5,18,2,7,4,6,1};
        Sort.selectSort(array3);
        System.out.println("测试选择排序"+Arrays.toString(array3));

        int[] array4 = {13,15,3,22,3,4,9,9,34};
        Sort.selectSort2(array4);
        System.out.println("测试双向选择排序2"+Arrays.toString(array4));

        int[] array5 = {13,15,3,22,3,4,9,9,34};
        Sort.heapSort(array5);
        System.out.println("测试堆排序"+Arrays.toString(array5));

        int[] array6 = {13,15,3,22,3,4,9,9,34};
        Sort.bubbleSort(array6);
        System.out.println("测试冒泡排序"+Arrays.toString(array6));

        int[] array7 = {6,1,2,7,9,7,4,5,10,8};
        Sort.quickSort(array7);
        System.out.println("测试快速（Hoare）排序"+Arrays.toString(array7));


        System.out.println("上面是自己给的数组测试是否能排序成功");
        System.out.println("===========随机数下测试速度==============");


        int[]array = new int[1_0000];//递归的越多在栈上开辟的内存就越大
        Test.initOrder(array);          //初始化数组，并且赋值可以是逆序的，也可以是顺序的
        Test.norOrder(array);//初始化数组，产生随机数，并赋值


        Test.testInsertSort(array);
        Test.testShellSort(array);
        Test.testSelectSort(array);
        Test.testSelecSort2(array);
        Test.testHeapSort(array);
        Test.testBubbleSort(array);
        Test.testHoareSort(array);
        //这里调整成十万个数据排序会造成栈溢出，在edit configuration（编辑配置
        // ）中可以调整jvm的内存大小


    }
}
